<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@ page import="api.IFacade"%>
<%@ page import="p3_entities.*"%>
<%@ page import="java.util.List"%>
<%@ page import="presentation.PhaseBook"%>

<%
	//HttpSession session = request.getSession(true);
	IFacade facadeBean = (IFacade) session
	.getAttribute("PhaseBookBean");

	if (facadeBean == null) {
		pageContext.forward("Login.jsp");
	} else {
		Balance loggedProfile = facadeBean.getLoggedProfile();
		Integer loggedUserId = loggedProfile.getUserId();

		String userName = request.getParameter("userName");
		Balance viewedProfile = facadeBean
		.getProfileByUsername(userName);
		Integer viewedUserId = viewedProfile.getUserId();
		
		List<Balance> friendsList = facadeBean.getMyFriends(viewedUserId);
%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">


<script type="text/javascript">

</script>




</head>
<body>

	<table>
	<%
		for (Balance friendProfile : friendsList) {
		String photoFName = "";
		if (friendProfile.getPhotoid() != null)
			photoFName=friendProfile.getPhotoid().getPhotoPath();
	%>
		<tr>
			<td align="left"><a href="MainPage.jsp?userName=<%= friendProfile.getEmail() %>"><%= friendProfile.getName() %></a></td>
			<td align="left"><a href="MainPage.jsp?userName=<%= friendProfile.getEmail() %>"><img id="imgProfilePhoto" alt="No profile photo" src="./image/<%= photoFName %>" style="max-height: 25px;"/></a></td>
		</tr>
	<%
		} // for each friend 
	%>
	</table>
	
</body>
</html>

<% } // else do bean != null %>